<?php
/**
 * Short description for file.
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.cake.libs.controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

/**
 * This is a placeholder class.
 * Create the same file in app/app_controller.php
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       cake
 * @subpackage    cake.cake.libs.controller
 */
class AppController extends Controller {
	
	public function verificaLogado() {
		if (! $this->Session->read ( 'Usuario.logado' )) {
			$this->Session->destroy ();
			$this->Session->setFlash ( 'Você não está logado.' );
			$this->redirect ( array ('controller' => 'logins', 'action' => 'index' ) );
		}
	
	}
	
	public function registraLogs($dados = null, $acao = null) {
		
		$logInstance = ClassRegistry::init ( 'Log' );
		
		if ($dados != null) {
			if (! empty ( $dados )) {
				if ($logInstance->save ( $dados )) {
					return $logInstance->id;
				}
			}
		} else if ($acao != null) {
			$dadosLog = array ('Log' => array (
				'CD_USUARIO' => $this->Session->read ( 'Usuario.cd_usuario' ), 
				'LOGIN' => $this->Session->read ( 'Usuario.login' ), 
				'DT_HR_ACESSO' => $this->Session->read ( 'Usuario.datahora_login' ), 
				'DT_HR_ACAO' => date ( 'Y-m-d H:i:s' ), 
				'ACAO' => $acao ) 
			);
			if ($logInstance->save ( $dadosLog )) {
				return $logInstance->id;
			} else {
				return false;
			}
		}
		
		return false;
	}

}
?>